//index.js
//获取应用实例
const app = getApp()
const Pager = require('components/aotoo/core')

const data = [
  {title: '40m²', id: 'mj'},
  {title: '有窗', id: 'cf'},
  {title: '禁烟', id: 'jy'},
  {title: '10-12层', id: 'lc'},
  {title: '不含早', id: 'zc'},
  {title: '不可加床', id: 'jc'},
  {title: '2名成人,1名儿童(12岁及以下)', id: 'kz'},
  {title: '1张大床1.8米 或 2张单人床1.2米', id: 'cx'},
  {title: '订单一经确认，不做退改。', id: 'cxx'},
]
const adapter = (data) => {
  const keyData = {mj: '面积', cf: '窗户', jy: '无烟', lc: '楼层', zc: '早餐', jc: '加床', kz: '可住', cx: '床型', cxx:'不消'}
  let output = []
  data.map((item, ii) => {
    output.push({
      title: [
        {title: keyData[item.id], itemClass: 'color-info'},
        {title: item.title, itemClass: 'ml-minor'}
      ],
      titleClass: 'flex-row size no-lh-x',
      itemClass: ('mb-default' + (ii < 5 ? ' wid-p50' : '') + (ii > 7 ? ' disN' : ''))
    })
  })
  return {
    data: output,
    footer: data.length > 7 ? {
      title: {title: '房型设施', itemClass: 'ss-tag tag-grey larger icon-after-toggle'}, itemClass: 'flex-row-center-center', aim: 'onShowMore2'
    }: {},
    listClass: 'flex-row-wrap color-default'
  }
}

Pager({
  data: {
    pages: Pager.list({
      type :{
        is: 'scroll', 
        'scroll-y': true
      },
      data: [
        {
          title: [
            {
              $$id: 'more',
              title: '酒店以好莱坞电影主题打造，拥有亚洲最高8字摩天轮。与 DC漫画合作推出的「蝙蝠侠」剧场。小朋友在儿童乐园可以 与华纳兄弟及漫画中的角色人物一起畅玩。酒店以好莱坞电影主题打造，拥有亚洲最高8字摩天轮。与 DC漫画合作推出的「蝙蝠侠」剧场。',
              itemClass: 'textellipsis-3',
            },
            {title: '展开', itemClass: 'size-sm icon-after-toggle item-icon', aim: 'onShowMore'}
          ],
          titleClass: 'tag-display p-default size-sm'
        },
        {
          img: {
            src: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1707371206,3427308196&fm=26&gp=0.jpg',
            itemClass: 'mb-minor br pic'
          },
          dot: [
            {title: '住进电影世界里-澳门新濠影汇酒店的奢豪体验', itemClass: 'size-title-sm no-lh-x'}
          ],
          itemClass: 'ss-card '
        },
        {
          img: {
            src: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1707371206,3427308196&fm=26&gp=0.jpg',
            itemClass: 'mb-default br pic'
          },
          '@list': adapter(data),
          itemClass: 'ss-card '
        },
        {
          title: {title: ' ', itemClass: 'icon-wx larger'},
          body: [{title: '关注微信公众号', itemClass: 'size-form fw-bold color-title mb10'},{title: '及时掌握最新活动消息和订单情况', itemClass: 'size-sm no-lh'}],
          footer: [{title: '去关注', itemClass: 'ss-button btn-grey plain small'}],
          itemClass: 'ss-card flex-row',
          bodyClass: 'ml-minor',
          footerClass: 'ml-auto'
        },
        {
          title: [{title: '订单信息', itemClass: 'color-title'}, {title: '预订须知', itemClass: 'ss-active icon-after-toggle'}],
          dot: [
            {title: '防疫期间，入住酒店需额外提供入境单，如无入境单或遗失入境单的客人无法入住，请见谅(有效期2020-09-10至2020-12-31', itemClass: 'item-body size-sm no-lh-x'}
          ],
          titleClass: 'flex-row-between-center size-sm no-lh mb-minor',
          itemClass: 'ss-card size-sm'
        },
        {
          tilte: ' ',
          itemClass: 'hei80'
        }
      ],
      listClass: 'hei-p100',
      itemClass: 'm-default'
    }),
    pagesBtn: Pager.item({
      title: {title: '我是Fixed层', itemClass: 'ss-button btn-grey plain'},
      itemClass: 'ss-nav'
    })
  },
  onShowMore2(e, parmas, inst) {
    let _newData = inst.parentInst.getData().data
    _newData = _newData.map(item => {
      if(item.itemClass.indexOf(' disN') > -1) {
        item.itemClass = item.itemClass.substring(0, item.itemClass.indexOf('disN'))
      }
      return item
    })
    inst.parentInst.update(_newData)
    inst.addClass('disN')
  },
  onShowMore(e, parmas, inst) {
    console.log(inst, '=======inst')
    inst.addClass('disN')
    this.$more.removeClass('textellipsis-3')
  },
  onMap(e, parmas, inst) {
    wx.navigateTo({
      url: '../map/index'
    })
  },
  onPhone(e, parmas, inst) {
    wx.makePhoneCall({
      phoneNumber: '13724140596' //仅为示例，并非真实的电话号码
    })
  },
  onCopy(e, parmas, inst) {
    const title = parmas.title
    wx.setClipboardData({
      data: title,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  },
  onShow: function () {},
  onReady: function () {},
  onLoad: function () {
    this.$more = this.getElementsById('more')
  },
})
